//////////////////////////////////////////////
// Get the mouse position.
//	e - event,
//	elem - html element
//////////////////////////////////////////////
function $(id) {
    var elem = document.getElementById(id);
    if (elem == null) {
        var elems = document.getElementsByName(id);
        if (elems != null && elems.length > 0) {
            elem = elems[0];
        }
    } 
    return elem;
}

function getCursorPosition(e, elem) {
    var x, y;
    if (e.pageX || e.pageY) {
		x = e.pageX;
		y = e.pageY;
    } else {
		x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollLTop + document.documentElement.scrollTop;
    }
    x -= elem.offsetLeft;
    y -= elem.offsetTop;
    return {x: x, y: y};
}

function handleMouseMove(e) {
	var cursorPos = getCursorPosition(e, $('myCanvas'));
	$('axis_x').value = cursorPos.x;
	$('axis_y').value = cursorPos.y;
}

$('elemId').addEventListener('mousemove', handleMouseMove, false);
